package com.lqg.bookLibrary.common.securityImpl;

import com.alibaba.fastjson2.JSON;
import com.lqg.bookLibrary.common.core.domain.JsonResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登出处理
 * */
@Component
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        JsonResult jsonResult = JsonResult.success("成功登出","success");
        String output = JSON.toJSONString(jsonResult);
        httpServletResponse.setContentType("text/json;charset=utf-8");
        httpServletResponse.setContentType("text/json;charset=utf-8");
        httpServletResponse.getWriter().write(output);
    }
}
